/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aljfce.business.utils;

import com.aljfce.business.entity.Notification;
import java.util.Comparator;

/**
 *
 * @author Antonio
 */
public class NotificationComparator implements Comparator<Notification> {
    /**
     * This method given two {@link Notification} objects compares their sending dates.
     * @param o1 
     * @param o2
     * @return -1 if o1 notification's sending date is before o2 notification's sending date, 0 otherwise
     */
    @Override
    public int compare(Notification o1, Notification o2) {
        if(o1==null||o2==null)
            throw new IllegalArgumentException("Notifications cannot be null");
        if (o1.getSendingDate().compareTo(o2.getSendingDate()) < 0){
            return -1;
        } 
        else {
            if (o1.getSendingDate().compareTo(o2.getSendingDate()) > 0) {
                return 1;
            }
            else return 0;
        }
    }
}
